﻿using Hotel.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UpLoadController : ControllerBase
    {
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        /// 
        [HttpPost("UploadImages")]
        public async Task<dynamic> UploadImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/Files/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                return Ok("http://localhost:23892/Files/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
